
figobj = findobj('name','FNU_plot');
if isempty(figobj)
    figobj = figure('name','FNU_plot');
end
set(groot,'CurrentFigure',figobj);

for n = 1:3
subplot(3,1,n);cla;
ax = gca;
ax.Box = 'on';
FontSize = 10;   %12~16
ax.FontSize = FontSize;
if n == 1
ax.Title.String = 'Comparasion of Three Algorithms: SAS, ANC, ATPD';
else
    ax.Title.String = '';
end
ax.Title.FontSize = FontSize+2;
if n == 3
ax.XLabel.String = 'Std HR(bpm)';
else
    ax.XLabel.String =  '';
end

ax.XLabel.FontSize = FontSize;
ax.YLabel.String = 'Measured HR(bpm)';
ax.YLabel.FontSize = FontSize;
%% axis setting
xdeta = 140;
xmin = 0; xmax = xmin + xdeta;
ax.XLim = [xmin xmax];
ax.XTick = xmin:20:xmax;
ax.XTickLabelMode = 'auto';
ax.XTickLabel = 40:20:60+xdeta;
ax.XAxis.FontSize = FontSize;
ymin = 40;ymax = 200;
ax.YLim = [ymin ymax];
ax.YAxis.FontSize = FontSize;
hold on

%% DFT analysis

switch n
    case 1
        plot(HR_VALUE(:,4),'k--');
        plot(HR_VALUE(:,1),'r-');
        l = legend( 'STD HR', 'SAS HR');
    case 2
        plot(HR_VALUE(:,4),'k--');
        plot(HR_VALUE(:,2),'g-');
        l = legend( 'STD HR', 'ANC HR');
    case 3
        plot(HR_VALUE(:,4),'k--');
        plot(HR_VALUE(:,3),'b-');
        l = legend( 'STD HR', 'ATPD HR');
    otherwise
        disp('other value')
end

l.Box = 'off';
l.Location = 'southeast';
l.FontSize = FontSize-2;
end
abs_ATPD = sum(abs(HR_VALUE(:,1)-HR_VALUE(:,4)))/length(HR_VALUE(:,4))
abs_ANC  = sum(abs(HR_VALUE(:,2)-HR_VALUE(:,4)))/length(HR_VALUE(:,4))
abs_SAS  = sum(abs(HR_VALUE(:,3)-HR_VALUE(:,4)))/length(HR_VALUE(:,4))

rel_ATPD = sum(abs(HR_VALUE(:,1)-HR_VALUE(:,4))./HR_VALUE(:,4))/length(HR_VALUE(:,4))
rel_ANC  = sum(abs(HR_VALUE(:,2)-HR_VALUE(:,4))./HR_VALUE(:,4))/length(HR_VALUE(:,4))
rel_SAS  = sum(abs(HR_VALUE(:,3)-HR_VALUE(:,4))./HR_VALUE(:,4))/length(HR_VALUE(:,4))

dev_ATPD = sum((HR_VALUE(:,1)-HR_VALUE(:,4)).^2)/(length(HR_VALUE(:,4)))
dev_ANC  = sum((HR_VALUE(:,2)-HR_VALUE(:,4)).^2)/(length(HR_VALUE(:,4)))
dev_SAS  = sum((HR_VALUE(:,3)-HR_VALUE(:,4)).^2)/(length(HR_VALUE(:,4)))

std_ATPD = sqrt(dev_ATPD)
std_ANC = sqrt(dev_ANC)
std_SAS = sqrt(dev_SAS)
